/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package group6;

import java.awt.Color;
import java.awt.Desktop;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Document;
import javax.swing.text.Highlighter;
import javax.swing.text.JTextComponent;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/**
 *
 * @author phamvanmot
 */
public class WikiLineNote extends javax.swing.JFrame {

    private boolean save = true;
    private boolean changefont = false;

    /**
     * Creates new form WikiLineNote
     */
    public WikiLineNote() {
        lookAndFeel();
        initComponents();
        this.setLocation(200, 100);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setFont();
    }
    
    /*
    * to find content of your note
    */
    class MyHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter {

        public MyHighlightPainter(Color color) {
            super(color);
        }
    }
    
    Highlighter.HighlightPainter myHighlightpainter = new MyHighlightPainter(Color.yellow);
    
    public void removehighlight(){
        Highlighter hight=txEnter.getHighlighter();
        Highlighter.Highlight[] hili=hight.getHighlights();
        for (int i = 0; i < hili.length; i++) {
            if(hili[i].getPainter() instanceof MyHighlightPainter){
                hight.removeHighlight(hili[i]);
            }
        }
    }

    public void highlight( String text) {
        removehighlight();
        try {
            Highlighter highlight = txEnter.getHighlighter();
            Document doc = txEnter.getDocument();
            String mytext = doc.getText(0, doc.getLength());
            int pos = 0;
            while ((pos = mytext.toUpperCase().indexOf(text.toUpperCase(), pos)) >= 0) {
                highlight.addHighlight(pos, pos + text.length(), myHighlightpainter);
                pos += text.length();
            }
        } catch (Exception e) {
        }
    }
    /*
     * Set font for Textarea while it's loadding
     */

    private void setFont() {
        Font fo = new Font("Times New Roman", Font.PLAIN, 14);
        txEnter.setFont(fo);
    }
    /*
     * Load tree while it's openning
     */

    /*
     * Set font for textarea
     */
    public void setFontText(String fontname, String fontstyle, String fontsize) {
        Font f;
        if (fontstyle.equals("Plain")) {
            f = new Font(fontname, Font.PLAIN, Integer.parseInt(fontsize));
        } else if (fontstyle.equals("Bold")) {
            f = new Font(fontname, Font.BOLD, Integer.parseInt(fontsize));
        } else {
            f = new Font(fontname, Font.ITALIC, Integer.parseInt(fontsize));
        }

        txEnter.setFont(f);
        changefont = true;
    }

    private void loadTree() {
        DefaultTreeModel model = (DefaultTreeModel) treeNote.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        String path = System.getProperty("user.dir");
        path += "\\My note";
        File file = new File(path);
        String[] list = file.list();
        for (int i = 0; i < list.length; i++) {
            root.add(new DefaultMutableTreeNode(list[i]));
            model.reload();
        }
    }

    /*
     * Load tree when open
     */
    private void setRoot(String rootname) {
        DefaultTreeModel model = (DefaultTreeModel) treeNote.getModel();
        DefaultMutableTreeNode setroot = new DefaultMutableTreeNode(rootname);
        model.setRoot(setroot);
//        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
//        String path = System.getProperty("user.dir");
//        path += "\\My note";        
//        File file = new File(path);
//        String[] list = file.list();
//        for (int i = 0; i < list.length; i++) {
//            root.add(new DefaultMutableTreeNode(list[i]));
//            model.reload();
//        }
    }
    /*
     Load tree when it saved a note
     */

    private void loadTree(String note) {
        DefaultTreeModel model = (DefaultTreeModel) treeNote.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        root.add(new DefaultMutableTreeNode(note));
        model.reload();
    }

    private void lookAndFeel() {// skin theo he thong
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {

        }
    }

    /*
     * set text for textarea
     */
    private void setText_Area() {
        txEnter.setEnabled(true);
        txEnter.setText("");
        txEnter.setEditable(true);
        txEnter.requestFocus();
    }

    /*
     * Set edit text for textarea
     */
    private void setEditText() {
        txEnter.requestFocus();
//        txEnter.setText("");
        txEnter.setEditable(false);
        txEnter.setEnabled(true);
    }

    private void setModifile() {
        txEnter.setEnabled(true);
        txEnter.setEditable(true);
        txEnter.requestFocus();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jToolBar1 = new javax.swing.JToolBar();
        btHome = new javax.swing.JButton();
        BtSearch = new javax.swing.JButton();
        btadd = new javax.swing.JButton();
        btDelete = new javax.swing.JButton();
        btpaste = new javax.swing.JButton();
        btViewadd = new javax.swing.JButton();
        btViewMul = new javax.swing.JButton();
        btB = new javax.swing.JButton();
        btI = new javax.swing.JButton();
        btU = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        treeNote = new javax.swing.JTree();
        jScrollPane2 = new javax.swing.JScrollPane();
        txEnter = new javax.swing.JTextArea();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        Mnnew = new javax.swing.JMenuItem();
        MnOpen = new javax.swing.JMenuItem();
        MnSave = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        Mnsaveas = new javax.swing.JMenuItem();
        MnExit = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        mnmodifire = new javax.swing.JMenuItem();
        MnDelete = new javax.swing.JMenuItem();
        Format = new javax.swing.JMenu();
        cbxmnword = new javax.swing.JCheckBoxMenuItem();
        MnFont = new javax.swing.JMenuItem();
        Mnword = new javax.swing.JMenu();
        mniexport = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jToolBar1.setRollover(true);

        btHome.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/TrangChu.png"))); // NOI18N
        btHome.setFocusable(false);
        btHome.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btHome.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btHome);

        BtSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Search.png"))); // NOI18N
        BtSearch.setFocusable(false);
        BtSearch.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BtSearch.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(BtSearch);

        btadd.setText("Add");
        btadd.setFocusable(false);
        btadd.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btadd.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btadd);

        btDelete.setText("Delete");
        btDelete.setFocusable(false);
        btDelete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btDelete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btDelete);

        btpaste.setText("Paste");
        btpaste.setFocusable(false);
        btpaste.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btpaste.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btpaste);

        btViewadd.setText("View +");
        btViewadd.setFocusable(false);
        btViewadd.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btViewadd.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btViewadd);

        btViewMul.setText("View -");
        btViewMul.setFocusable(false);
        btViewMul.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btViewMul.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btViewMul);

        btB.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btB.setText("B");
        btB.setFocusable(false);
        btB.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btB.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btB);

        btI.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        btI.setText("I");
        btI.setFocusable(false);
        btI.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btI.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btI);

        btU.setFont(new java.awt.Font("Times New Roman", 0, 10)); // NOI18N
        btU.setText("U");
        btU.setFocusable(false);
        btU.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btU.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btU);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("My note");
        treeNote.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        treeNote.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                treeNoteMouseClicked(evt);
            }
        });
        treeNote.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                treeNoteValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(treeNote);

        txEnter.setColumns(20);
        txEnter.setRows(5);
        txEnter.setEnabled(false);
        txEnter.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txEnterKeyPressed(evt);
            }
        });
        jScrollPane2.setViewportView(txEnter);

        jMenu1.setText("File");

        Mnnew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        Mnnew.setText("New ");
        Mnnew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnnewActionPerformed(evt);
            }
        });
        jMenu1.add(Mnnew);

        MnOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        MnOpen.setText("Open");
        MnOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnOpenActionPerformed(evt);
            }
        });
        jMenu1.add(MnOpen);

        MnSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        MnSave.setText("Save");
        MnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnSaveActionPerformed(evt);
            }
        });
        jMenu1.add(MnSave);

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Find");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        Mnsaveas.setText("Save as");
        Mnsaveas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnsaveasActionPerformed(evt);
            }
        });
        jMenu1.add(Mnsaveas);

        MnExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        MnExit.setText("Exit");
        MnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnExitActionPerformed(evt);
            }
        });
        jMenu1.add(MnExit);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        mnmodifire.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.SHIFT_MASK));
        mnmodifire.setText("Modifire");
        mnmodifire.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnmodifireActionPerformed(evt);
            }
        });
        jMenu2.add(mnmodifire);

        MnDelete.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, java.awt.event.InputEvent.SHIFT_MASK));
        MnDelete.setText("Delete");
        jMenu2.add(MnDelete);

        jMenuBar1.add(jMenu2);

        Format.setText("Format");

        cbxmnword.setSelected(true);
        cbxmnword.setText("Word Wrap");
        Format.add(cbxmnword);

        MnFont.setText("Font");
        MnFont.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnFontActionPerformed(evt);
            }
        });
        Format.add(MnFont);

        jMenuBar1.add(Format);

        Mnword.setText("View");

        mniexport.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.SHIFT_MASK));
        mniexport.setText("Export");
        mniexport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniexportActionPerformed(evt);
            }
        });
        Mnword.add(mniexport);

        jMenuBar1.add(Mnword);

        jMenu4.setText("Help");
        jMenuBar1.add(jMenu4);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 736, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addComponent(jScrollPane2))
                .addGap(13, 13, 13))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void treeNoteValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_treeNoteValueChanged
//        jTree1.getSelectionModel().setSelectionMode
//            (TreeSelectionModel.SINGLE_TREE_SELECTION);
//        jTree1.addTreeSelectionListener((TreeSelectionListener) this);
//         DefaultMutableTreeNode node = (DefaultMutableTreeNode)
//                       jTree1.getLastSelectedPathComponent();
//                    if (node == null)
//              //Nothing is selected.     
//              return;
//
//              Object nodeInfo = node.getUserObject();
//              if (node.isLeaf()) {
//                  BookInfo book = (BookInfo)nodeInfo;
//                  displayURL(book.bookURL);
//              } else {
//                  displayURL(helpURL); 
//              }
    }//GEN-LAST:event_treeNoteValueChanged

    /*
     * show savedialog to save note
     */
    private void operateFile(String title) {
        JFileChooser chooser = new JFileChooser();
        int choos = -1;
        chooser.setDialogTitle(title);
        String path = System.getProperty("user.dir");
        path += "\\My note";
        File defaultpath = new File(path);
        chooser.setCurrentDirectory(defaultpath);
        choos = chooser.showSaveDialog(null);
        if (choos == JFileChooser.APPROVE_OPTION) {
            File child = chooser.getSelectedFile();
            DefaultTreeModel model = (DefaultTreeModel) treeNote.getModel();
            File parent = child.getParentFile();
            if (model.getRoot().toString().equals("My note")) {
                setRoot(parent.getName());
                writeFile(child);
                loadTree(child.getName());
            } else if (model.getRoot().toString().equals(parent.getName())) {
                writeFile(child);
                loadTree(child.getName());
            } else {
                setRoot(parent.getName());
                writeFile(child);
                loadTree(child.getName());
            }
        }
    }

    /*
     * Open note
     */
    private void OpenAllFile(String title) {
        JFileChooser choose = new JFileChooser();
        int choos = -1;
        choose.setDialogTitle(title);
        String path = System.getProperty("user.dir");
        path += "\\My note";
        File defaultpath = new File(path);
        choose.setCurrentDirectory(defaultpath);
        choos = choose.showOpenDialog(null);
        if (choos == JFileChooser.APPROVE_OPTION) {
            File child = choose.getSelectedFile();
            File parent = child.getParentFile();
            treeNote.clearSelection();
            setRoot(parent.getName());
            File[] listchild = parent.listFiles();
            for (File f : listchild) {
                loadTree(f.getName());
            }
        }
    }

    /*
     * lấy nội dung ghi chú từ file
     */
    String content_note;

    private void readFile(File file) {
        try {
            FileReader fr = new FileReader(file);
            BufferedReader br = new BufferedReader(fr);
            String line;
            String s = "";
            while ((line = br.readLine()) != null) {
                s += line + "\n";
            }
            content_note = s;
            br.close();
            fr.close();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error to open file: " + e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    /*
     * lưu ghi chú vào file
     */
    private void writeFile(File file) {
        try {
            file.createNewFile();
            FileWriter fw = new FileWriter(file);
            BufferedWriter bw = new BufferedWriter(fw);
            String data = txEnter.getText();
            bw.write(data);
            bw.close();
            fw.close();
            save = true;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error to save file: " + e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void MnnewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnnewActionPerformed
        if (save == true) {
            setText_Area();
        } else {
            if (selectnote.equals("")) {
                int result = JOptionPane.showConfirmDialog(null, "Do you want to save your note", "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (result == JOptionPane.YES_OPTION) {
                    operateFile("Save your note");
                    setEditText();
                    selectnote = "";
                } else {
                    setText_Area();
                }
            } else {
                String path = System.getProperty("user.dir");
                path += "\\My note\\" + selectnote;
                File f = new File(path);
                writeFile(f);
                setEditText();
                selectnote = "";
            }
        }
    }//GEN-LAST:event_MnnewActionPerformed

    private void MnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnSaveActionPerformed
        if (selectnote.equals("")) {
            operateFile("Save your note");
            setEditText();
            selectnote = "";
        } else {
            String path = System.getProperty("user.dir");
            path += "\\My note\\" + selectnote;
            File f = new File(path);
            writeFile(f);
            setEditText();
            selectnote = "";
        }
    }//GEN-LAST:event_MnSaveActionPerformed
    String selectnote = "";

    /*
     * Load content of a note
     */
    
    String pathexport="";
    private void treeNoteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_treeNoteMouseClicked
        selectnote = treeNote.getSelectionPath().toString().replaceAll("[\\[\\]]", "").replace(", ", "\\");
        String path = System.getProperty("user.dir");
        path += "\\My note\\" + selectnote;
        pathexport=selectnote;
        File file = new File(path);
        readFile(file);
        txEnter.setText(content_note);
        setEditText();
//        selectnote = "";
    }//GEN-LAST:event_treeNoteMouseClicked

    /*
     * change textarea
     */
    private void txEnterKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txEnterKeyPressed
        if (evt.getKeyCode() != -1) {
            save = false;
//            selectnote=pathexport;
        }
    }//GEN-LAST:event_txEnterKeyPressed

    /*
     * Save with other name
     */
    private void MnsaveasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnsaveasActionPerformed
        operateFile("Save your note");
        setEditText();
    }//GEN-LAST:event_MnsaveasActionPerformed

    private void MnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnExitActionPerformed
        if (save == true) {
            System.exit(0);
        } else {
            if (selectnote.equals("")) {
                int result = JOptionPane.showConfirmDialog(null, "Do you want to save your note", "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (result == JOptionPane.YES_OPTION) {
                    operateFile("Save your note");
                    System.exit(0);
                } else {
                    System.exit(0);
                }
            } else {
                File f = new File(selectnote);
                writeFile(f);
            }
        }
    }//GEN-LAST:event_MnExitActionPerformed

    private void MnFontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnFontActionPerformed
        FontForm fontform = new FontForm();
        fontform.setForm(this);
    }//GEN-LAST:event_MnFontActionPerformed

    private void mnmodifireActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnmodifireActionPerformed
        setModifile();
    }//GEN-LAST:event_mnmodifireActionPerformed

    private void MnOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnOpenActionPerformed
        if (save == true) {
            OpenAllFile("Open your note");
        } else {
            if (selectnote.equals("")) {
                int result = JOptionPane.showConfirmDialog(null, "Do you want to save your note", "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (result == JOptionPane.YES_OPTION) {
                    operateFile("Save your note");
                    selectnote = "";
                } else {
                    OpenAllFile("Open your note");
                }
            } else {
                String path = System.getProperty("user.dir");
                path += "\\My note\\" + selectnote;
                File f = new File(path);
                writeFile(f);
                setEditText();
                selectnote = "";
            }
        }
    }//GEN-LAST:event_MnOpenActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        if (save == true) {
            System.exit(0);
        } else {
            if (selectnote.equals("")) {
                int result = JOptionPane.showConfirmDialog(null, "Do you want to save your note", "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (result == JOptionPane.YES_OPTION) {
                    operateFile("Save your note");
                    System.exit(0);
                } else {
                    System.exit(0);
                }
            } else {
                File f = new File(selectnote);
                writeFile(f);
            }
        }
    }//GEN-LAST:event_formWindowClosing

    private void mniexportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniexportActionPerformed
        try {
            String path = System.getProperty("user.dir");
            path += "\\My note\\" + pathexport;
            File f=new File(path);
            if(f.exists()){
                if(Desktop.isDesktopSupported()){                    
                    Desktop.getDesktop().open(f);
                }
                else{
                    JOptionPane.showMessageDialog(null, "Awt Desktop isn't supported","Error",JOptionPane.ERROR_MESSAGE);
                }
            }else{
                JOptionPane.showMessageDialog(null, "File doesn't exits","Error",JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_mniexportActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        Find find=new Find();
        find.setForm(this);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the NimMobus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(WikiLineNote.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(WikiLineNote.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(WikiLineNote.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(WikiLineNote.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new WikiLineNote().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtSearch;
    private javax.swing.JMenu Format;
    private javax.swing.JMenuItem MnDelete;
    private javax.swing.JMenuItem MnExit;
    private javax.swing.JMenuItem MnFont;
    private javax.swing.JMenuItem MnOpen;
    private javax.swing.JMenuItem MnSave;
    private javax.swing.JMenuItem Mnnew;
    private javax.swing.JMenuItem Mnsaveas;
    private javax.swing.JMenu Mnword;
    private javax.swing.JButton btB;
    private javax.swing.JButton btDelete;
    private javax.swing.JButton btHome;
    private javax.swing.JButton btI;
    private javax.swing.JButton btU;
    private javax.swing.JButton btViewMul;
    private javax.swing.JButton btViewadd;
    private javax.swing.JButton btadd;
    private javax.swing.JButton btpaste;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JCheckBoxMenuItem cbxmnword;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenuItem mniexport;
    private javax.swing.JMenuItem mnmodifire;
    private javax.swing.JTree treeNote;
    private javax.swing.JTextArea txEnter;
    // End of variables declaration//GEN-END:variables
}
